import Vue from 'vue'

import 'normalize.css/normalize.css' // 重置样式 它让不同的浏览器在渲染网页元素的时候形式更统一

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css' // 全局引入elementui
// import locale from 'element-ui/lib/locale/lang/en' // 引入 语言包

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

import { i18n } from '@/lang'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})

// 自定义指令解决图片加载失败问题
// Vue.directive('imgerror', {
//   inserted(dom, bingding, vNode) {
//     // 图片加载失败触发img的error事件，触发后让他替换为默认图片
//     dom.onerror = function() {
//       dom.src = bingding.value
//     }
//   }
// })

// 封装js, 全部导入自定义指令遍历注册
import * as directives from '@/directives'
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
})

// 全局注册组件
// import PageTools from '@/components/PageTools'

// Vue.component('PageTools', PageTools)

//! 使用Vue.use方式注册
import plugins from '@/components'
Vue.use(plugins)

// 全局注册过滤器
import * as filters from '@/filters'

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
